<?php/*  PHP version 5  Copyright (c) 2002-2019ECISP.CN、EarcLink.COM  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220*/


use application\ESPCMS_FileUpload;
use inc_application\link\PublicLink;

class FileUpload {

    public static function in_FileUpload() {
        global $espcms_web_templates, $espcms_command;
        $lanpack = $espcms_web_templates->geto('lngpack');
        if (!preg_match('/^[\w]{2,50}$/i', $_GET['inputidname']) || !preg_match('/^[\w]{2,50}$/i', $_GET['upFileType'])) {
            exit($lanpack['db_err']);
        }
        $attrname = $_GET['inputidname'];
        $inputtype = $_GET['upFileType'];
        $link_array = array('attrname' => $attrname, 'inputtype' => $inputtype);
        $espcms_web_templates->into('file_save_link', PublicLink::get_fileupload('upfiesave', $link_array));

        $php_upload_max_filesize = ini_get('file_uploads') ? intval(ini_get('upload_max_filesize')) : 2;
        $espcms_web_templates->into('php_upload_max_filesize', $php_upload_max_filesize);

        $net_upload_max_filesize = intval($espcms_command['WEB_UPFILE_SIZE']);
        $espcms_web_templates->into('net_upload_max_filesize', $net_upload_max_filesize);

        $chunksize = $php_upload_max_filesize > 5 ? 5 * 1024 * 1024 : $php_upload_max_filesize * 1024 * 1024;
        $espcms_web_templates->into('chunksize', $chunksize);

        $upload_max_filesize_byte = $net_upload_max_filesize * 1024 * 1024;
        $espcms_web_templates->into('upload_max_filesize_byte', $upload_max_filesize_byte);
        $espcms_web_templates->into('path', 'public');
        $espcms_web_templates->into('inputtype', $inputtype);
        $espcms_web_templates->into('upfile_ext', $_GET['upFileType'] == 'file' ? $espcms_command['UPFILE_FILE_OTHER_TYPE'] : $espcms_command['UPFILE_FILE_PIC_TYPE']);
        $espcms_web_templates->into('tokenkey', token('file_upload'));
        $espcms_web_templates->output('public/fileupload', 'fileupload', false, false);
    }

    public static function in_FileSave() {
        global $espcms_command;
        if (!preg_match('/^[\w]{2,50}$/i', $_GET['inputidname']) || !preg_match('/^[\w]{2,50}$/i', $_GET['upFileType'])) {
            exit;
        }

        $upFileType = $_GET['upFileType'] == 'file' ? 'file' : 'image';
        $isWater = $_POST['isWater'] && $upFileType == 'image' ? true : false;

        $fileName = $_FILES['espcms_webupfilename']['name'] ? $_FILES['espcms_webupfilename']['name'] : uniqid("file_");

        $espcms_command['UPFILE_SIZE'] = $espcms_command['WEB_UPFILE_SIZE'];

        $espcms_command['UPFILE_SAVAPATH'] = 'upload/';

        $uploadFileArray = ESPCMS_FileUpload::intoFile($_FILES['espcms_webupfilename'], $espcms_command, $upFileType, false, $isWater, false, 0, 1);

















        $uploadFileArray['inuptypeid'] = $_GET['inputidname'];
        $outJOSN = json_encode($uploadFileArray);
        exit($outJOSN);
    }

}
